/*
===============================================================================
                    EntitySpaces 2009 by EntitySpaces, LLC
             Persistence Layer and Business Objects for Microsoft .NET
             EntitySpaces(TM) is a legal trademark of EntitySpaces, LLC
                          http://www.entityspaces.net
===============================================================================
EntitySpaces Version : 2009.2.1214.0
EntitySpaces Driver  : SQL
Date Generated       : 1/26/2010 10:20:34 AM
===============================================================================
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.ComponentModel;
using System.Xml.Serialization;


using EntitySpaces.Core;
using EntitySpaces.Interfaces;
using EntitySpaces.DynamicQuery;


using DotNetNuke.Framework.Providers;


namespace DNNspot.LiveChat.DataModel
{

	[Serializable]
	abstract public class esPortalSettingCollection : esEntityCollection
	{
		public esPortalSettingCollection()
		{

		}

		protected override string GetCollectionName()
		{
			return "PortalSettingCollection";
		}

		#region Query Logic
		protected void InitQuery(esPortalSettingQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			query.es2.Connection = ((IEntityCollection)this).Connection;
		}

		protected bool OnQueryLoaded(DataTable table)
		{
			this.PopulateCollection(table);
			return (this.RowCount > 0) ? true : false;
		}
		
		protected override void HookupQuery(esDynamicQuery query)
		{
			this.InitQuery(query as esPortalSettingQuery);
		}
		#endregion
		
		virtual public PortalSetting DetachEntity(PortalSetting entity)
		{
			return base.DetachEntity(entity) as PortalSetting;
		}
		
		virtual public PortalSetting AttachEntity(PortalSetting entity)
		{
			return base.AttachEntity(entity) as PortalSetting;
		}
		
		virtual public void Combine(PortalSettingCollection collection)
		{
			base.Combine(collection);
		}
		
		new public PortalSetting this[int index]
		{
			get
			{
				return base[index] as PortalSetting;
			}
		}

		public override Type GetEntityType()
		{
			return typeof(PortalSetting);
		}
	}



	[Serializable]
	abstract public class esPortalSetting : esEntity
	{
		/// <summary>
		/// Used internally by the entity's DynamicQuery mechanism.
		/// </summary>
		virtual protected esPortalSettingQuery GetDynamicQuery()
		{
			return null;
		}

		public esPortalSetting()
		{

		}

		public esPortalSetting(DataRow row)
			: base(row)
		{

		}
		
		#region LoadByPrimaryKey
		public virtual bool LoadByPrimaryKey(System.Int32 portalId, System.String settingName)
		{
			if(this.es.Connection.SqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(portalId, settingName);
			else
				return LoadByPrimaryKeyStoredProcedure(portalId, settingName);
		}

		public virtual bool LoadByPrimaryKey(esSqlAccessType sqlAccessType, System.Int32 portalId, System.String settingName)
		{
			if (sqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(portalId, settingName);
			else
				return LoadByPrimaryKeyStoredProcedure(portalId, settingName);
		}

		private bool LoadByPrimaryKeyDynamic(System.Int32 portalId, System.String settingName)
		{
			esPortalSettingQuery query = this.GetDynamicQuery();
			query.Where(query.PortalId == portalId, query.SettingName == settingName);
			return query.Load();
		}

		private bool LoadByPrimaryKeyStoredProcedure(System.Int32 portalId, System.String settingName)
		{
			esParameters parms = new esParameters();
			parms.Add("PortalId",portalId);			parms.Add("SettingName",settingName);
			return this.Load(esQueryType.StoredProcedure, this.es.spLoadByPrimaryKey, parms);
		}
		#endregion
		
		
		
		#region Properties
		
		
		public override void SetProperties(IDictionary values)
		{
			foreach (string propertyName in values.Keys)
			{
				this.SetProperty(propertyName, values[propertyName]);
			}
		}

		public override void SetProperty(string name, object value)
		{
			if(this.Row == null) this.AddNew();
			
			esColumnMetadata col = this.Meta.Columns.FindByPropertyName(name);
			if (col != null)
			{
				if(value == null || value is System.String)
				{				
					// Use the strongly typed property
					switch (name)
					{							
						case "PortalId": this.str.PortalId = (string)value; break;							
						case "SettingName": this.str.SettingName = (string)value; break;							
						case "SettingValue": this.str.SettingValue = (string)value; break;							
						case "CreatedDate": this.str.CreatedDate = (string)value; break;							
						case "ModifiedDate": this.str.ModifiedDate = (string)value; break;
					}
				}
				else
				{
					switch (name)
					{	
						case "PortalId":
						
							if (value == null || value is System.Int32)
								this.PortalId = (System.Int32?)value;
							break;
						
						case "CreatedDate":
						
							if (value == null || value is System.DateTime)
								this.CreatedDate = (System.DateTime?)value;
							break;
						
						case "ModifiedDate":
						
							if (value == null || value is System.DateTime)
								this.ModifiedDate = (System.DateTime?)value;
							break;
					

						default:
							break;
					}
				}
			}
			else if(this.Row.Table.Columns.Contains(name))
			{
				this.Row[name] = value;
			}
			else
			{
				throw new Exception("SetProperty Error: '" + name + "' not found");
			}
		}
		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_PortalSettings.PortalId
		/// </summary>
		virtual public System.Int32? PortalId
		{
			get
			{
				return base.GetSystemInt32(PortalSettingMetadata.ColumnNames.PortalId);
			}
			
			set
			{
				base.SetSystemInt32(PortalSettingMetadata.ColumnNames.PortalId, value);
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_PortalSettings.SettingName
		/// </summary>
		virtual public System.String SettingName
		{
			get
			{
				return base.GetSystemString(PortalSettingMetadata.ColumnNames.SettingName);
			}
			
			set
			{
				base.SetSystemString(PortalSettingMetadata.ColumnNames.SettingName, value);
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_PortalSettings.SettingValue
		/// </summary>
		virtual public System.String SettingValue
		{
			get
			{
				return base.GetSystemString(PortalSettingMetadata.ColumnNames.SettingValue);
			}
			
			set
			{
				base.SetSystemString(PortalSettingMetadata.ColumnNames.SettingValue, value);
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_PortalSettings.CreatedDate
		/// </summary>
		virtual public System.DateTime? CreatedDate
		{
			get
			{
				return base.GetSystemDateTime(PortalSettingMetadata.ColumnNames.CreatedDate);
			}
			
			set
			{
				base.SetSystemDateTime(PortalSettingMetadata.ColumnNames.CreatedDate, value);
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_PortalSettings.ModifiedDate
		/// </summary>
		virtual public System.DateTime? ModifiedDate
		{
			get
			{
				return base.GetSystemDateTime(PortalSettingMetadata.ColumnNames.ModifiedDate);
			}
			
			set
			{
				base.SetSystemDateTime(PortalSettingMetadata.ColumnNames.ModifiedDate, value);
			}
		}
		
		#endregion	

		#region String Properties


		[BrowsableAttribute( false )]
		public esStrings str
		{
			get
			{
				if (esstrings == null)
				{
					esstrings = new esStrings(this);
				}
				return esstrings;
			}
		}


		[Serializable]
		sealed public class esStrings
		{
			public esStrings(esPortalSetting entity)
			{
				this.entity = entity;
			}
			
	
			public System.String PortalId
			{
				get
				{
					System.Int32? data = entity.PortalId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.PortalId = null;
					else entity.PortalId = Convert.ToInt32(value);
				}
			}
				
			public System.String SettingName
			{
				get
				{
					System.String data = entity.SettingName;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.SettingName = null;
					else entity.SettingName = Convert.ToString(value);
				}
			}
				
			public System.String SettingValue
			{
				get
				{
					System.String data = entity.SettingValue;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.SettingValue = null;
					else entity.SettingValue = Convert.ToString(value);
				}
			}
				
			public System.String CreatedDate
			{
				get
				{
					System.DateTime? data = entity.CreatedDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedDate = null;
					else entity.CreatedDate = Convert.ToDateTime(value);
				}
			}
				
			public System.String ModifiedDate
			{
				get
				{
					System.DateTime? data = entity.ModifiedDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ModifiedDate = null;
					else entity.ModifiedDate = Convert.ToDateTime(value);
				}
			}
			

			private esPortalSetting entity;
		}
		#endregion

		#region Query Logic
		protected void InitQuery(esPortalSettingQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			query.es2.Connection = ((IEntity)this).Connection;
		}

		[System.Diagnostics.DebuggerNonUserCode]
		protected bool OnQueryLoaded(DataTable table)
		{
			bool dataFound = this.PopulateEntity(table);

			if (this.RowCount > 1)
			{
				throw new Exception("esPortalSetting can only hold one record of data");
			}

			return dataFound;
		}
		#endregion
		
		[NonSerialized]
		private esStrings esstrings;
	}


	
	public partial class PortalSetting : esPortalSetting
	{

		
		/// <summary>
		/// Used internally by the entity's hierarchical properties.
		/// </summary>
		protected override List<esPropertyDescriptor> GetHierarchicalProperties()
		{
			List<esPropertyDescriptor> props = new List<esPropertyDescriptor>();
			
		
			return props;
		}	
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PreSave.
		/// </summary>
		protected override void ApplyPreSaveKeys()
		{
		}
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PostSave.
		/// </summary>
		protected override void ApplyPostSaveKeys()
		{
		}
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PostOneToOneSave.
		/// </summary>
		protected override void ApplyPostOneSaveKeys()
		{
		}
		
	}



	[Serializable]
	abstract public class esPortalSettingQuery : esDynamicQuery
	{
		override protected IMetadata Meta
		{
			get
			{
				return PortalSettingMetadata.Meta();
			}
		}	
		

		public esQueryItem PortalId
		{
			get
			{
				return new esQueryItem(this, PortalSettingMetadata.ColumnNames.PortalId, esSystemType.Int32);
			}
		} 
		
		public esQueryItem SettingName
		{
			get
			{
				return new esQueryItem(this, PortalSettingMetadata.ColumnNames.SettingName, esSystemType.String);
			}
		} 
		
		public esQueryItem SettingValue
		{
			get
			{
				return new esQueryItem(this, PortalSettingMetadata.ColumnNames.SettingValue, esSystemType.String);
			}
		} 
		
		public esQueryItem CreatedDate
		{
			get
			{
				return new esQueryItem(this, PortalSettingMetadata.ColumnNames.CreatedDate, esSystemType.DateTime);
			}
		} 
		
		public esQueryItem ModifiedDate
		{
			get
			{
				return new esQueryItem(this, PortalSettingMetadata.ColumnNames.ModifiedDate, esSystemType.DateTime);
			}
		} 
		
	}



    [System.Diagnostics.DebuggerDisplay("Count = {Count}")]
	[Serializable]
	[XmlType("PortalSettingCollection")]
	public partial class PortalSettingCollection : esPortalSettingCollection, IEnumerable<PortalSetting>
	{
		public PortalSettingCollection()
		{

		}
		
		public static implicit operator List<PortalSetting>(PortalSettingCollection coll)
		{
			List<PortalSetting> list = new List<PortalSetting>();
			
			foreach (PortalSetting emp in coll)
			{
				list.Add(emp);
			}
			
			return list;
		}
		
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return  PortalSettingMetadata.Meta();
			}
		}
		
		
		
		override protected esDynamicQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new PortalSettingQuery();
				this.InitQuery(query);
			}
			return this.query;
		}
		
		override protected esEntity CreateEntityForCollection(DataRow row)
		{
			return new PortalSetting(row);
		}

		override protected esEntity CreateEntity()
		{
			return new PortalSetting();
		}
		
		
		#endregion


		[BrowsableAttribute( false )]
		public PortalSettingQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new PortalSettingQuery();
					base.InitQuery(this.query);
				}

				return this.query;
			}
		}

		public void QueryReset()
		{
			this.query = null;
		}

		public bool Load(PortalSettingQuery query)
		{
			this.query = query;
			base.InitQuery(this.query);
			return this.Query.Load();
		}
		
		public PortalSetting AddNew()
		{
			PortalSetting entity = base.AddNewEntity() as PortalSetting;
			
			return entity;
		}

		public PortalSetting FindByPrimaryKey(System.Int32 portalId, System.String settingName)
		{
			return base.FindByPrimaryKey(portalId, settingName) as PortalSetting;
		}


		#region IEnumerable<PortalSetting> Members

		IEnumerator<PortalSetting> IEnumerable<PortalSetting>.GetEnumerator()
		{
			System.Collections.IEnumerable enumer = this as System.Collections.IEnumerable;
			System.Collections.IEnumerator iterator = enumer.GetEnumerator();

			while(iterator.MoveNext())
			{
				yield return iterator.Current as PortalSetting;
			}
		}

		#endregion
		
		private PortalSettingQuery query;
	}


	/// <summary>
	/// Encapsulates the 'DNNspot_LiveChat_PortalSettings' table
	/// </summary>

    [System.Diagnostics.DebuggerDisplay("PortalSetting ({PortalId},{SettingName})")]
	[Serializable]
	public partial class PortalSetting : esPortalSetting
	{
		public PortalSetting()
		{

		}
	
		public PortalSetting(DataRow row)
			: base(row)
		{

		}
		
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return PortalSettingMetadata.Meta();
			}
		}
		
		
		
		override protected esPortalSettingQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new PortalSettingQuery();
				this.InitQuery(query);
			}
			return this.query;
		}
		#endregion
		



		[BrowsableAttribute( false )]
		public PortalSettingQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new PortalSettingQuery();
					base.InitQuery(this.query);
				}

				return this.query;
			}
		}

		public void QueryReset()
		{
			this.query = null;
		}
		

		public bool Load(PortalSettingQuery query)
		{
			this.query = query;
			base.InitQuery(this.query);
			return this.Query.Load();
		}
		
		private PortalSettingQuery query;
	}



    [System.Diagnostics.DebuggerDisplay("LastQuery = {es.LastQuery}")]
	[Serializable]
		
	public partial class PortalSettingQuery : esPortalSettingQuery
	{
		public PortalSettingQuery()
		{

		}		
		
		public PortalSettingQuery(string joinAlias)
		{
			this.es.JoinAlias = joinAlias;
		}	

        override protected string GetQueryName()
        {
            return "PortalSettingQuery";
        }
		
			
	}


	[Serializable]
	public partial class PortalSettingMetadata : esMetadata, IMetadata
	{
		#region Protected Constructor
		protected PortalSettingMetadata()
		{
			_columns = new esColumnMetadataCollection();
			esColumnMetadata c;

			c = new esColumnMetadata(PortalSettingMetadata.ColumnNames.PortalId, 0, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = PortalSettingMetadata.PropertyNames.PortalId;
			c.IsInPrimaryKey = true;
			c.NumericPrecision = 10;
			_columns.Add(c);
				
			c = new esColumnMetadata(PortalSettingMetadata.ColumnNames.SettingName, 1, typeof(System.String), esSystemType.String);
			c.PropertyName = PortalSettingMetadata.PropertyNames.SettingName;
			c.IsInPrimaryKey = true;
			c.CharacterMaxLength = 50;
			_columns.Add(c);
				
			c = new esColumnMetadata(PortalSettingMetadata.ColumnNames.SettingValue, 2, typeof(System.String), esSystemType.String);
			c.PropertyName = PortalSettingMetadata.PropertyNames.SettingValue;
			c.CharacterMaxLength = 2000;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(PortalSettingMetadata.ColumnNames.CreatedDate, 3, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = PortalSettingMetadata.PropertyNames.CreatedDate;
			c.HasDefault = true;
			c.Default = @"(getdate())";
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(PortalSettingMetadata.ColumnNames.ModifiedDate, 4, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = PortalSettingMetadata.PropertyNames.ModifiedDate;
			c.HasDefault = true;
			c.Default = @"(getdate())";
			c.IsNullable = true;
			_columns.Add(c);
				
		}
		#endregion	
	
		static public PortalSettingMetadata Meta()
		{
			return meta;
		}	
		
		public Guid DataID
		{
			get { return base._dataID; }
		}	
		
		public bool MultiProviderMode
		{
			get { return false; }
		}		

		public esColumnMetadataCollection Columns
		{
			get	{ return base._columns; }
		}
		
		#region ColumnNames
		public class ColumnNames
		{ 
			 public const string PortalId = "PortalId";
			 public const string SettingName = "SettingName";
			 public const string SettingValue = "SettingValue";
			 public const string CreatedDate = "CreatedDate";
			 public const string ModifiedDate = "ModifiedDate";
		}
		#endregion	
		
		#region PropertyNames
		public class PropertyNames
		{ 
			 public const string PortalId = "PortalId";
			 public const string SettingName = "SettingName";
			 public const string SettingValue = "SettingValue";
			 public const string CreatedDate = "CreatedDate";
			 public const string ModifiedDate = "ModifiedDate";
		}
		#endregion	

		public esProviderSpecificMetadata GetProviderMetadata(string mapName)
		{
			MapToMeta mapMethod = mapDelegates[mapName];

			if (mapMethod != null)
				return mapMethod(mapName);
			else
				return null;
		}
		
		#region MAP esDefault
		
		static private int RegisterDelegateesDefault()
		{
			// This is only executed once per the life of the application
			lock (typeof(PortalSettingMetadata))
			{
				if(PortalSettingMetadata.mapDelegates == null)
				{
					PortalSettingMetadata.mapDelegates = new Dictionary<string,MapToMeta>();
				}
				
				if (PortalSettingMetadata.meta == null)
				{
					PortalSettingMetadata.meta = new PortalSettingMetadata();
				}
				
				MapToMeta mapMethod = new MapToMeta(meta.esDefault);
				mapDelegates.Add("esDefault", mapMethod);
				mapMethod("esDefault");
			}
			return 0;
		}			

		private esProviderSpecificMetadata esDefault(string mapName)
		{
			if(!_providerMetadataMaps.ContainsKey(mapName))
			{
				esProviderSpecificMetadata meta = new esProviderSpecificMetadata();
				

				meta.AddTypeMap("PortalId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("SettingName", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("SettingValue", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("CreatedDate", new esTypeMap("datetime", "System.DateTime"));
				meta.AddTypeMap("ModifiedDate", new esTypeMap("datetime", "System.DateTime"));			
				
				
				
				ProviderConfiguration providerConfiguration = ProviderConfiguration.GetProviderConfiguration("data");
				Provider provider = (Provider)providerConfiguration.Providers[providerConfiguration.DefaultProvider];

				string objectQualifier = provider.Attributes["objectQualifier"];

				if ((objectQualifier != string.Empty) && (objectQualifier.EndsWith("_") == false))
				{
					objectQualifier += "_";
				}

				if (objectQualifier != string.Empty)
				{
					meta.Source = objectQualifier + "DNNspot_LiveChat_PortalSettings";
					meta.Destination = objectQualifier + "DNNspot_LiveChat_PortalSettings";
					
					meta.spInsert = objectQualifier + "proc_DNNspot_LiveChat_PortalSettingsInsert";				
					meta.spUpdate = objectQualifier + "proc_DNNspot_LiveChat_PortalSettingsUpdate";		
					meta.spDelete = objectQualifier + "proc_DNNspot_LiveChat_PortalSettingsDelete";
					meta.spLoadAll = objectQualifier + "proc_DNNspot_LiveChat_PortalSettingsLoadAll";
					meta.spLoadByPrimaryKey = objectQualifier + "proc_DNNspot_LiveChat_PortalSettingsLoadByPrimaryKey";
				}
				else
				{
					meta.Source = "DNNspot_LiveChat_PortalSettings";
					meta.Destination = "DNNspot_LiveChat_PortalSettings";
									
					meta.spInsert = "proc_DNNspot_LiveChat_PortalSettingsInsert";				
					meta.spUpdate = "proc_DNNspot_LiveChat_PortalSettingsUpdate";		
					meta.spDelete = "proc_DNNspot_LiveChat_PortalSettingsDelete";
					meta.spLoadAll = "proc_DNNspot_LiveChat_PortalSettingsLoadAll";
					meta.spLoadByPrimaryKey = "proc_DNNspot_LiveChat_PortalSettingsLoadByPrimaryKey";
				}
				
				
				this._providerMetadataMaps["esDefault"] = meta;
			}
			
			return this._providerMetadataMaps["esDefault"];
		}

		#endregion

		static private PortalSettingMetadata meta;
		static protected Dictionary<string, MapToMeta> mapDelegates;
		static private int _esDefault = RegisterDelegateesDefault();
	}
}
